/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.sandbox.trade

import com.almasb.fxgl.app.*
import com.almasb.fxgl.dsl.*
import com.almasb.fxgl.input.*
import javafx.scene.input.*
import javafx.scene.paint.*
import javafx.scene.shape.*

/**
 *
 *
 * @author Almas Baimagambetov (AlmasB) (almaslvl@gmail.com)
 */
class ArcadeShopSample : GameApplication() {
	
	private var shopState: ArcadeShopState? = null
	
	override fun initSettings(settings: GameSettings) {
	
	}
	
	override fun initInput() {
		getInput().addAction(object : UserAction("Open Shop") {
			override fun onActionBegin() {
				getGameController().pushSubScene(shopState!!)
			}
		}, KeyCode.F)
	}
	
	override fun initGameVars(vars: MutableMap<String, Any>) {
		vars["bonus.atk.level"] = 0
		vars["bonus.def.level"] = 0
		vars["bonus.hp.level"] = 0
		vars["bonus.atk.value"] = 0
		vars["bonus.def.value"] = 0
		vars["bonus.hp.value"] = 0
	}
	
	override fun initGame() {
		getGameState().intProperty("bonus.atk.value").bind(getGameState().intProperty("bonus.atk.level").multiply(10))
		getGameState().intProperty("bonus.def.value").bind(getGameState().intProperty("bonus.def.level").multiply(25))
		getGameState().intProperty("bonus.hp.value").bind(getGameState().intProperty("bonus.hp.level").multiply(5))
		
		shopState = ArcadeShopState()
		shopState!!.addItem(ArcadeShopItem("ATK", "Increases ATK", 100, 10, 0, Circle(10.0, 10.0, 10.0, Color.GOLD)))
	}
	
	override fun initUI() {
		val text = getUIFactory().newText("", Color.BLACK, 16.0)
		text.textProperty().bind(getGameState().intProperty("bonus.atk.value").asString("ATK: %d ")
			.concat(getGameState().intProperty("bonus.def.value").asString("DEF: %d "))
			.concat(getGameState().intProperty("bonus.hp.value").asString("HP: %d")))
		
		text.translateY = 50.0
		
		getGameScene().addUINode(text)
	}
}

fun main(args: Array<String>) {
	GameApplication.launch(ArcadeShopSample::class.java, args)
}

